package com.pj.wisdomlogistics.ui.activity;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.pj.wisdomlogistics.R;
import com.pj.wisdomlogistics.cons.Cons;
import com.pj.wisdomlogistics.entity.MeetingPlanSimpleInfo;
import com.pj.wisdomlogistics.entity.MeetingSimpleInfo;
import com.pj.wisdomlogistics.mvp.contract.MeetingPlanContract;
import com.pj.wisdomlogistics.mvp.frame.MvpActivity;
import com.pj.wisdomlogistics.mvp.frame.base.BaseView;
import com.pj.wisdomlogistics.mvp.presenter.MeetingPlanPresenter;
import com.pj.wisdomlogistics.other.EventCenter;
import com.pj.wisdomlogistics.ui.adapter.MeetingPlanSimpleAdapter;
import com.pj.wisdomlogistics.utils.ActivityManagerUtil;
import com.pj.wisdomlogistics.utils.CustomToast;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class MeetingPlanActivity extends MvpActivity<MeetingPlanPresenter> implements MeetingPlanContract.View, MeetingPlanSimpleAdapter.onItemClick {
    @BindView(R.id.rv_meeting_plan)
    RecyclerView mRvMeetingPlan;
    @BindView(R.id.tv_noData)
    TextView mTvNoData;

    private MeetingPlanSimpleAdapter mAdapter;
    private int id;

    private MeetingSimpleInfo mInfo;

    @Override
    protected BaseView getBaseView() {
        return this;
    }

    @Override
    public void initView() {
        ultimateBar.setColorBar(ContextCompat.getColor(this , R.color.text_blue));

        id = getIntent().getIntExtra(Cons.MeetingInfo.MEETING_SELECT_ID , -1);
        mInfo = (MeetingSimpleInfo) getIntent().getSerializableExtra(Cons.MeetingInfo.MEETING_COUNT);

        mRvMeetingPlan.setLayoutManager(new LinearLayoutManager(this , LinearLayoutManager.VERTICAL , false));
        mAdapter = new MeetingPlanSimpleAdapter(this);
        mRvMeetingPlan.setAdapter(mAdapter);
        mAdapter.setListener(this);

        mPresenter.meetingTimeAxis(id);
        showProgressDialog();
    }

    @Override
    public void initData() {

    }

    @Override
    public int getContentView() {
        return R.layout.activity_meeting_plan;
    }

    @Override
    public boolean isApplyEventBus() {
        return false;
    }

    @Override
    public boolean isApplyButterKnife() {
        return true;
    }

    @Override
    public void onEventCome(EventCenter eventCenter) {

    }


    @OnClick({R.id.iv_back, R.id.tv_next})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                ActivityManagerUtil.create().finishActivity();
                break;
            case R.id.tv_next:
                Intent mIntent = new Intent(this, ApplyMeetingActivity.class);
                mIntent.putExtra(Cons.MeetingInfo.MEETING_SELECT_ID , id);
                mIntent.putExtra(Cons.MeetingInfo.MEETING_COUNT , mInfo);
                startActivity(mIntent);
                break;
        }
    }

    @Override
    public void onError(String errorMsg) {
        dismissProgressDialog();
        CustomToast.showToast(this , errorMsg , 1000);
    }

    @Override
    public void Success(List<MeetingPlanSimpleInfo> mList) {
        dismissProgressDialog();
        if(mList.size() == 0 || mList == null){
            mTvNoData.setVisibility(View.VISIBLE);
        }else{
            mAdapter.setList(mList);
        }
    }

    @Override
    public void call(String tel) {
        Uri uri = Uri.parse("tel:" + tel);
        Intent intent = new Intent(Intent.ACTION_DIAL, uri);
        startActivity(intent);
    }
}
